//
//  WBarFrameWorkHelpExtension.swift
//  Pods
//
//  Created by LC_WJH on 2017/10/10.
//
//

import Foundation

//辅助工具扩展
public extension Date{
    
    ///String 类型回date
    func formatString(formatString: String) -> String {
        //yyyy-MM-dd hh:mm:ss
        let form = DateFormatter()
        form.dateFormat = formatString
        return form.string(from: self);
    }
    
}

//辅助工具扩展
public extension String{
    
    ///String 类型回date
    func dateFromFromString(formatString: String) -> Date? {
        
        //yyyy-MM-dd hh:mm:ss
        let form = DateFormatter()
        form.dateFormat = formatString
        return form.date(from: self);
    }
    
}

//辅助工具扩展
public extension Double{
    
    ///double类型的时间日期辅助格式化
    func dateWithFromString(formatString: String) -> String {
        
        //yyyy-MM-dd hh:mm:ss
        
        let temp = self * 0.001
        if temp <= 0 {
            return ""
        }
        let date = Date(timeIntervalSince1970: temp)
        let form = DateFormatter()
        form.dateFormat = formatString
        return form.string(from: date)
    }
    
}

//辅助工具扩展
public extension Int{
    
    ///double类型的时间日期辅助格式化
    func dateWithFromString(formatString: String) -> String {
        
        //yyyy-MM-dd hh:mm:ss
        
        let temp:Double = Double(self) * 0.001
        if temp <= 0 {
            return ""
        }
        let date = Date(timeIntervalSince1970: temp)
        let form = DateFormatter()
        form.dateFormat = formatString
        return form.string(from: date)
    }
    
}
